package com.ruoyi.laiqianba.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 渠道/产品计价类型
 */
@Getter
public enum ChargeTypeEnum {

    UV(1, "UV计价"),
    REG(2, "注册计价"),
    UNION(3, "联登计价"),
    FLOW(4, "信息流计价"),
    ;

    private Integer value;
    private String name;

    ChargeTypeEnum(Integer value, String name){
        this.value = value;
        this.name = name;
    }

    public static List<Map<String, String>> getChannelMapList(){
        List<Map<String, String>> resultList = new ArrayList<>();
        for (ChargeTypeEnum chargeTypeEnum : values()) {
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("key", chargeTypeEnum.getName());
            itemMap.put("value", String.valueOf(chargeTypeEnum.getValue()));
            resultList.add(itemMap);
        }
        return resultList;
    }

    public static String getNameByValue(Integer chargeType) {
        for (ChargeTypeEnum chargeTypeEnum : values()) {
            if (ObjectUtil.equals(chargeType, chargeTypeEnum.getValue())){
                return chargeTypeEnum.getName();
            }
        }
        return String.valueOf(chargeType);
    }

    public static Integer getValueByName(Integer name) {
        for (ChargeTypeEnum chargeTypeEnum : values()) {
            if (ObjectUtil.equals(name, chargeTypeEnum.getName())){
                return chargeTypeEnum.getValue();
            }
        }
        return name;
    }
}
